<template>
    <div class="app-container">
        <el-form class="lookForm" :model="queryParams" ref="queryForm" size="mini" :inline="true" label-width="140px">
            <el-form-item label="岗位名称" prop="postName">
                <el-input v-model="queryParams.postName" placeholder="请输入岗位名称" clearable
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="设岗部门" prop="deptName">
                <el-input v-model="queryParams.deptName" placeholder="请输入设岗部门" clearable
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="负责人姓名" prop="fzrName">
                <el-input v-model="queryParams.fzrName" placeholder="请输入负责人姓名" clearable
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <!-- <el-form-item label="指导老师姓名" prop="zdlsName">
                <el-input v-model="queryParams.zdlsName" placeholder="请输入指导老师姓名" clearable
                    @keyup.enter.native="handleQuery" />
            </el-form-item> -->
            <el-form-item label="校区" prop="campusName">
                <el-input v-model="queryParams.campusName" placeholder="请输入校区" clearable
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="工作地点" prop="workAddr">
                <el-input v-model="queryParams.workAddr" placeholder="请输入工作地点" clearable
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="审核状态" prop="applyStatus">
                <el-select v-model="queryParams.applyStatus" placeholder="请选择审核状态" clearable>
                    <el-option v-for="dict in dict.type.qgzx_apply_status" :key="dict.value" :label="dict.label"
                        :value="dict.value" />
                </el-select>
            </el-form-item>
            <el-form-item label="申请时间" prop="applyTime">
                <el-date-picker clearable v-model="queryParams.applyTime" type="date" value-format="yyyy-MM-dd"
                    placeholder="请选择申请时间">
                </el-date-picker>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="applyVClick">申请岗位</el-button>
                <el-button type="success" plain icon="el-icon-view" size="mini" @click="lookChangeVClick">查看申请修改 岗位的设岗人数
                    记录</el-button>
            </el-col>
        </el-row>

        <el-table v-loading="loading" :data="tableData">
            <el-table-column label="#" align="center" prop="id" />
            <el-table-column label="岗位名称" align="center" prop="postName" />
            <el-table-column label="设岗部门" align="center" prop="deptName" />
            <el-table-column label="设岗人数" align="center" prop="postCount" />
            <el-table-column label="审核状态" align="center" prop="applyStatus">
                <template slot-scope="scope">
                    <dict-tag :options="dict.type.qgzx_apply_status" :value="scope.row.applyStatus" />
                </template>
            </el-table-column>
            <el-table-column label="申请时间" align="center" prop="applyTime" width="180">
                <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.applyTime) }}</span>
                </template>
            </el-table-column>

            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <el-button v-if="scope.row.applyStatus == '0'" size="mini" type="text" icon="el-icon-edit"
                        @click="doEdit(scope.row)">修改</el-button>

                    <el-button v-if="scope.row.applyStatus == '3'" size="mini" type="text" icon="el-icon-edit"
                        @click="changePostNum(scope.row)">修改设岗人数</el-button>
                    <el-button v-if="scope.row.applyStatus == '1' || scope.row.applyStatus == '0'" size="mini"
                        type="text" icon="el-icon-circle-close" @click="cancelApply(scope.row)">取消申请</el-button>
                    <el-button size="mini" type="text" icon="el-icon-view" @click="lookVClick(scope.row)">查看</el-button>
                    <el-button v-if="scope.row.applyStatus == '11'" size="mini" type="text" icon="el-icon-refresh"
                        @click="reVClick(scope.row)">重新提交</el-button>
                </template>
            </el-table-column>
        </el-table>

        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize" @pagination="getList" />


        <el-dialog title="重新提交岗位申请" :visible.sync="replyV" append-to-body fullscreen>
            <el-form :rules="rules" :model="replyForm" size="mini" ref="replyForm" label-width="148px">
                <el-row>
                    <el-col :span="8">
                        <el-form-item label="岗位名称" prop="postName">
                            <el-input :maxlength="100" v-model="replyForm.postName" placeholder="请输入岗位名称" />
                        </el-form-item>
                    </el-col>

                    <el-col :span="8">
                        <el-form-item label="设岗部门" prop="deptId">
                            <treeselect size="mini" v-model="replyForm.deptId" :options="deptOptions1"
                                :normalizer="normalizer" placeholder="请选择设岗部门" />
                        </el-form-item>
                    </el-col>

                    <el-col :span="8">
                        <el-form-item label="设岗人数" prop="postCount">
                            <el-input min="0" type="number" v-model="replyForm.postCount" placeholder="请输入设岗人数" />
                        </el-form-item>
                    </el-col>

                    <el-col :span="12">
                        <el-form-item label="负责人" prop="fzrName">
                            <TeacherSelect :valueProps="{ value: 'employeeId', label: 'name' }"
                                v-model="replyForm.fzrNo" />
                        </el-form-item>
                    </el-col>

                    <el-col :span="6">
                        <el-form-item label="联系电话" prop="zdlsPhone">
                            <el-input v-model="replyForm.zdlsPhone" placeholder="请输入指导老师联系电话" />
                        </el-form-item>
                    </el-col>

                    <el-col :span="6">
                        <el-form-item label="岗位类型" prop="postType">
                            <el-select clearable v-model="replyForm.postType" placeholder="请选择岗位类型">
                                <el-option label="固定岗位A" value="固定岗位A"></el-option>
                                <el-option label="固定岗位B" value="固定岗位B"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>

                    <el-col :span="8">
                        <el-form-item label="付酬方式">
                            <el-input :value="replyForm.postType === '固定岗位A' ? '按天' : '按小时'" disabled />
                        </el-form-item>
                    </el-col>

                    <el-col :span="8">
                        <el-form-item v-if="replyForm.postType != '固定岗位A'" label="付酬标准">
                            <el-input value="15.00" disabled />
                        </el-form-item>
                    </el-col>

                    <el-col :span="8">
                        <el-form-item label="预计金额(元/月/人)" prop="willMoney">
                            <el-input :max="1990" :min="0" type="number" v-model="replyForm.willMoney"
                                placeholder="预计每人每月发放多少薪资" />
                        </el-form-item>
                    </el-col>

                    <el-col :span="12">
                        <el-form-item label="预计金额合计(元/月)" prop="willMoneyTotal">
                            <el-input readonly type="number" v-model="replyForm.willMoneyTotal"
                                placeholder="预计每月该岗位总共发放多少薪资，=设岗人数*预计金额（元/月/人）" />
                        </el-form-item>
                    </el-col>

                    <el-col :span="24">
                        <el-form-item label="岗位职责" prop="workNeed">
                            <el-input :maxlength="200" type="textarea" v-model="replyForm.workNeed"
                                placeholder="岗位职责，需要学生做什么" />
                        </el-form-item>
                    </el-col>


                    <el-col :span="24">
                        <el-form-item label="技能要求" prop="skillNeed">
                            <el-input :maxlength="200" type="textarea" v-model="replyForm.skillNeed"
                                placeholder="针对岗位职责，对学生的技能、素质等有什么要求" />
                        </el-form-item>
                    </el-col>

                    <el-col :span="24">
                        <el-form-item label="每周工作时长" prop="weekTime">
                            <el-input type="number" v-model="replyForm.weekTime" placeholder="请输入每周工作时长" />
                        </el-form-item>
                    </el-col>

                    <el-col :span="8">
                        <el-form-item label="校区" prop="campusName">
                            <el-select clearable v-model="replyForm.campusName" placeholder="请选择校区">
                                <el-option label="长堽校区" value="长堽校区"></el-option>
                                <el-option label="里建校区" value="里建校区"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>

                    <el-col :span="16">
                        <el-form-item label="工作地点" prop="workAddr">
                            <el-input :maxlength="200" v-model="replyForm.workAddr" placeholder="请输入工作地点" />
                        </el-form-item>
                    </el-col>

                    <el-col :span="8">
                        <el-form-item label="备注" prop="remark">
                            <el-input :maxlength="200" v-model="replyForm.remark" placeholder="请输入备注" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="申请理由" prop="applyReason">
                            <el-input :maxlength="200" type="textarea" v-model="replyForm.applyReason"
                                placeholder="请输入申请理由" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label=" " prop="remark">
                            <el-button type="success" @click="doReply" plain size="mini">重新提交</el-button>
                        </el-form-item>
                    </el-col>

                </el-row>
            </el-form>
        </el-dialog>



        <el-dialog title="岗位申请" :visible.sync="applyV" append-to-body fullscreen>
            <el-form :rules="rules" :model="applyForm" size="mini" ref="applyForm" label-width="148px">
                <el-row>
                    <el-col :span="8">
                        <el-form-item label="岗位名称" prop="postName">
                            <el-input :maxlength="100" v-model="applyForm.postName" placeholder="请输入岗位名称" />
                        </el-form-item>
                    </el-col>

                    <el-col :span="8">
                        <el-form-item label="设岗部门" prop="deptId">
                            <treeselect size="mini" v-model="applyForm.deptId" :options="deptOptions1"
                                :normalizer="normalizer" placeholder="请选择设岗部门" />
                        </el-form-item>
                    </el-col>

                    <el-col :span="8">
                        <el-form-item label="设岗人数" prop="postCount">
                            <el-input min="0" type="number" v-model="applyForm.postCount" placeholder="请输入设岗人数" />
                        </el-form-item>
                    </el-col>

                    <el-col :span="12">
                        <el-form-item label="负责人" prop="fzrName">
                            <TeacherSelect :valueProps="{ value: 'employeeId', label: 'name' }"
                                v-model="applyForm.fzrNo" />
                        </el-form-item>
                    </el-col>

                    <el-col :span="6">
                        <el-form-item label="联系电话" prop="zdlsPhone">
                            <el-input v-model="applyForm.zdlsPhone" placeholder="请输入指导老师联系电话" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="岗位类型" prop="postType">
                            <el-select clearable v-model="applyForm.postType" placeholder="请选择岗位类型">
                                <el-option label="固定岗位A" value="固定岗位A"></el-option>
                                <el-option label="固定岗位B" value="固定岗位B"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>

                    <el-col :span="8">
                        <el-form-item label="付酬方式">
                            <el-input :value="applyForm.postType === '固定岗位A' ? '按天' : '按小时'" disabled />
                        </el-form-item>
                    </el-col>

                    <el-col :span="8" v-if="applyForm.postType != '固定岗位A'">
                        <el-form-item label="付酬标准">
                            <el-input value="15.00" disabled />
                        </el-form-item>
                    </el-col>

                    <el-col :span="8">
                        <el-form-item label="预计金额(元/月/人)" prop="willMoney">
                            <el-input :readonly="applyForm.postType === '固定岗位A' ? true : false" :max="1990" :min="0"
                                type="number" v-model="applyForm.willMoney" placeholder="预计每人每月发放多少薪资" />
                        </el-form-item>
                    </el-col>

                    <el-col :span="12">
                        <el-form-item label="预计金额合计(元/月)" prop="willMoneyTotal">
                            <el-input readonly type="number" v-model="applyForm.willMoneyTotal"
                                placeholder="预计每月该岗位总共发放多少薪资，=设岗人数*预计金额（元/月/人）" />
                        </el-form-item>
                    </el-col>

                    <el-col :span="24">
                        <el-form-item label="岗位职责" prop="workNeed">
                            <el-input :maxlength="200" type="textarea" v-model="applyForm.workNeed"
                                placeholder="岗位职责，需要学生做什么" />
                        </el-form-item>
                    </el-col>


                    <el-col :span="24">
                        <el-form-item label="技能要求" prop="skillNeed">
                            <el-input :maxlength="200" type="textarea" v-model="applyForm.skillNeed"
                                placeholder="针对岗位职责，对学生的技能、素质等有什么要求" />
                        </el-form-item>
                    </el-col>

                    <el-col :span="24">
                        <el-form-item label="每周工作时长" prop="weekTime">
                            <el-input type="number" v-model="applyForm.weekTime" placeholder="请输入每周工作时长" />
                        </el-form-item>
                    </el-col>

                    <el-col :span="8">
                        <el-form-item label="校区" prop="campusName">
                            <el-select clearable v-model="applyForm.campusName" placeholder="请选择校区">
                                <el-option label="长堽校区" value="长堽校区"></el-option>
                                <el-option label="里建校区" value="里建校区"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>

                    <el-col :span="16">
                        <el-form-item label="工作地点" prop="workAddr">
                            <el-input :maxlength="200" v-model="applyForm.workAddr" placeholder="请输入工作地点" />
                        </el-form-item>
                    </el-col>

                    <el-col :span="8">
                        <el-form-item label="备注" prop="remark">
                            <el-input :maxlength="200" v-model="applyForm.remark" placeholder="请输入备注" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="申请理由" prop="applyReason">
                            <el-input :maxlength="200" type="textarea" v-model="applyForm.applyReason"
                                placeholder="请输入申请理由" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label=" " prop="remark">
                            <el-button type="primary" @click="doSave" plain size="mini">保存</el-button>
                            <el-button type="success" @click="doApply" plain size="mini">提交</el-button>
                        </el-form-item>
                    </el-col>

                </el-row>
            </el-form>
        </el-dialog>


        <el-dialog title="查看" :visible.sync="lookV" append-to-body fullscreen>
            <el-form class="lookForm" size="mini" ref="applyForm" label-width="148px">
                <el-row>
                    <el-col :span="8">
                        <el-form-item label="岗位名称" prop="postName">
                            <el-input v-model="lookForm.postName" readonly />
                        </el-form-item>
                    </el-col>

                    <el-col :span="8">
                        <el-form-item label="设岗部门" prop="deptId">
                            <el-input v-model="lookForm.deptName" readonly />
                        </el-form-item>
                    </el-col>

                    <el-col :span="8">
                        <el-form-item label="设岗人数" prop="postCount">
                            <el-input v-model="lookForm.postCount" readonly />
                        </el-form-item>
                    </el-col>

                    <el-col :span="8">
                        <el-form-item label="负责人" prop="fzrName">
                            <el-input v-model="lookForm.fzrName" readonly />
                        </el-form-item>
                    </el-col>

                    <!-- <el-col :span="8">
                        <el-form-item label="指导老师" prop="zdlsName">
                            <el-input v-model="lookForm.zdlsName" readonly />
                        </el-form-item>
                    </el-col> -->

                    <el-col :span="8">
                        <el-form-item label="联系电话" prop="zdlsPhone">
                            <el-input v-model="lookForm.zdlsPhone" readonly />
                        </el-form-item>
                    </el-col>

                    <el-col :span="8">
                        <el-form-item label="付酬方式">
                            <el-input value="按小时" disabled />
                        </el-form-item>
                    </el-col>

                    <el-col :span="8">
                        <el-form-item label="付酬标准" v-if="lookForm.postType != '固定岗位A'">
                            <el-input value="15.00" disabled />
                        </el-form-item>
                    </el-col>

                    <el-col :span="8">
                        <el-form-item label="预计金额(元/月/人)" prop="willMoney">
                            <el-input v-model="lookForm.willMoney" readonly />
                        </el-form-item>
                    </el-col>

                    <el-col :span="12">
                        <el-form-item label="预计金额合计(元/月)" prop="willMoneyTotal">
                            <el-input readonly v-model="lookForm.willMoneyTotal" />
                        </el-form-item>
                    </el-col>

                    <el-col :span="24">
                        <el-form-item label="岗位职责" prop="workNeed">
                            <el-input type="textarea" v-model="lookForm.workNeed" readonly />
                        </el-form-item>
                    </el-col>


                    <el-col :span="24">
                        <el-form-item label="技能要求" prop="skillNeed">
                            <el-input type="textarea" v-model="lookForm.skillNeed" readonly />
                        </el-form-item>
                    </el-col>

                    <el-col :span="24">
                        <el-form-item label="每周工作时长" prop="weekTime">
                            <el-input v-model="lookForm.weekTime" readonly />
                        </el-form-item>
                    </el-col>

                    <el-col :span="8">
                        <el-form-item label="校区" prop="campusName">
                            <el-input v-model="lookForm.campusName" readonly />
                        </el-form-item>
                    </el-col>

                    <el-col :span="16">
                        <el-form-item label="工作地点" prop="workAddr">
                            <el-input v-model="lookForm.workAddr" readonly />
                        </el-form-item>
                    </el-col>

                    <el-col :span="8">
                        <el-form-item label="岗位类型" prop="postType">
                            <el-input v-model="lookForm.postType" readonly />
                        </el-form-item>
                    </el-col>

                    <el-col :span="8">
                        <el-form-item label="备注" prop="remark">
                            <el-input v-model="lookForm.remark" readonly />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="申请理由" prop="applyReason">
                            <el-input type="textarea" v-model="lookForm.applyReason" readonly />
                        </el-form-item>
                    </el-col>
                    <el-col :span="4">
                        <el-form-item label="审核状态" prop="applyStatus">
                            <dict-tag :options="dict.type.qgzx_apply_status" :value="lookForm.applyStatus" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8" v-if="!isEmpty(lookForm.returnMsg)">
                        <el-form-item label="驳回理由" prop="returnMsg">
                            <el-input type="textarea" v-model="lookForm.returnMsg" readonly />
                        </el-form-item>
                    </el-col>

                </el-row>
            </el-form>
            <hr />
            <el-steps :active="getStep(lookForm)">
                <el-step title="部门制表人申请岗位" description=""></el-step>
                <el-step title="部门领导审批" :status="isEmpty(lookForm.deptCmt) ? 'wait' : getStepStatus(lookForm.deptCmt)">
                    <template slot="description">
                        <div>
                            {{ isEmpty(lookForm.deptNoName) ? '' : lookForm.deptNoName }}
                        </div>
                        <div>
                            {{ isEmpty(lookForm.deptCmt) ? '' : lookForm.deptCmt }}
                        </div>
                        <div>
                            {{ isEmpty(lookForm.deptTime) ? '' : lookForm.deptTime }}
                        </div>
                    </template>
                </el-step>
                <el-step title="资助办领导审批" :status="isEmpty(lookForm.highCmt) ? 'wait' : getStepStatus(lookForm.highCmt)">
                    <template slot="description">
                        <div>
                            {{ isEmpty(lookForm.highNoName) ? '' : lookForm.highNoName }}
                        </div>
                        <div>
                            {{ isEmpty(lookForm.highCmt) ? '' : lookForm.highCmt }}
                        </div>
                        <div>
                            {{ isEmpty(lookForm.highTime) ? '' : lookForm.highTime }}
                        </div>
                    </template>
                </el-step>
            </el-steps>
            <hr />
            <el-form label-width="148px" size="mini">
                <el-row>
                    <el-col :span="8" v-if="!isEmpty(lookForm.deptCmt)">
                        <el-form-item label="部门意见">
                            <el-radio-group v-model="lookForm.deptCmt" disabled>
                                <el-radio :label="'同意'">同意</el-radio>
                                <el-radio :label="'拒绝'">拒绝</el-radio>
                                <el-radio :label="'驳回'">驳回</el-radio>
                            </el-radio-group>
                        </el-form-item>
                        <el-form-item label="部门签章" v-if="lookForm.deptSign">
                            <img :src="baseurl + lookForm.deptSign" width="200px" height="50px">
                        </el-form-item>
                    </el-col>
                    <el-col :span="8" v-if="!isEmpty(lookForm.highCmt)">
                        <el-form-item label="资助办意见">
                            <el-radio-group v-model="lookForm.highCmt" disabled>
                                <el-radio :label="'同意'">同意</el-radio>
                                <el-radio :label="'拒绝'">拒绝</el-radio>
                                <el-radio :label="'驳回'">驳回</el-radio>
                            </el-radio-group>
                        </el-form-item>
                        <el-form-item label="资助办签章">
                            <img :src="baseurl + lookForm.highSign" width="200px" height="50px">
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
        </el-dialog>


        <el-dialog :visible.sync="changeV" title="修改设岗人数" append-to-body :close-on-click-modal="false">
            <el-form class="lookForm" size="mini" ref="changeForm" label-width="148px">
                <el-form-item label="当前在岗人数">
                    <el-input v-model="changeForm.inCount" disabled readonly />
                </el-form-item>
                <el-form-item label="当前设岗人数">
                    <el-input v-model="changeForm.oldCount" disabled readonly />
                </el-form-item>
                <el-form-item label="修改后的设岗人数" prop="newCount">
                    <el-input type="number" v-model="changeForm.newCount" placeholder="请输入修改后的在岗人数" />
                </el-form-item>
                <el-form-item label="申请理由" prop="applyReason">
                    <el-input type="textarea" v-model="changeForm.applyReason" placeholder="请输入申请理由" />
                </el-form-item>
                <el-form-item>
                    <el-button @click="doChange" size="mini">提交</el-button>
                    <br />
                    <span style="color:red">*修改勤工助学设岗人数后仍然需要 <u>部门领导--资助办领导审批</u></span>
                </el-form-item>
            </el-form>
        </el-dialog>

        <el-dialog :visible.sync="lookChangeV" title="查看申请修改岗位设岗人数记录" append-to-body fullscreen>
            <el-table v-loading="changeLoading" :data="changeTableData">
                <el-table-column label="#" align="center" prop="id" />
                <el-table-column label="岗位名称" align="center" prop="postName" />
                <el-table-column label="修改的设岗人数" align="center" prop="newCount" />
                <el-table-column label="审核状态" align="center" prop="applyStatus">
                    <template slot-scope="scope">
                        <dict-tag :options="dict.type.qgzx_apply_status" :value="scope.row.applyStatus" />
                    </template>
                </el-table-column>
                <el-table-column label="申请时间" align="center" prop="applyTime" width="180">
                    <template slot-scope="scope">
                        <span>{{ parseTime(scope.row.applyTime) }}</span>
                    </template>
                </el-table-column>

                <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                    <template slot-scope="scope">
                        <el-button v-if="scope.row.applyStatus == '1'" size="mini" type="text"
                            icon="el-icon-circle-close" @click="cancelChange(scope.row)">取消申请</el-button>
                    </template>
                </el-table-column>
            </el-table>

            <pagination v-show="changeTotal > 0" :total="changeTotal" :page.sync="changeQueryParams.pageNum"
                :limit.sync="changeQueryParams.pageSize" @pagination="getChangeList" />
        </el-dialog>


    </div>
</template>
<script>

import { cancelApply, doApply, doReply, doSave, listOwnApply } from "@/api/workstudy/post";

import { countStuPostInByPostId } from "@/api/workstudy/stuPost";

import { cancelChange, doChange, listOwnChange } from "@/api/workstudy/change";


import { fullLoading, isEmpty, isPositiveInteger } from "@/api/helpFunc";

import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";

import { noAuthList as listDept } from "@/api/system/dept";

import TeacherSelect from '@/views/components/TeacherSelect/index';

import { getUserProfile } from "@/api/system/user";


export default {
    name: "workstudy-apply",
    components: { Treeselect, TeacherSelect },
    dicts: ['qgzx_apply_status'],
    data() {
        return {
            isEmpty,
            loading: false,
            total: 0,
            tableData: [],

            queryParams: {
                pageNum: 1,
                pageSize: 10,
                postName: null,
            },

            applyV: false,
            applyForm: {

            },

            lookV: false,
            lookForm: {},

            replyV: false,
            replyForm: {}, //重新提交表单


            deptOptions1: [],
            rules: {
                postName: [
                    { required: true, message: "岗位名称不能为空", trigger: "blur" }
                ],
                postCount: [
                    { required: true, message: "设岗人数不能为空", trigger: "blur" }
                ],
                zdlsPhone: [
                    { required: true, message: "不能为空", trigger: "blur" }
                ],
                willMoney: [
                    { required: true, message: "不能为空", trigger: "blur" }
                ],
                willMoneyTotal: [
                    { required: true, message: "不能为空", trigger: "blur" }
                ],
                workNeed: [
                    { required: true, message: "不能为空", trigger: "blur" }
                ],
                skillNeed: [
                    { required: true, message: "不能为空", trigger: "blur" }
                ],
                weekTime: [
                    { required: true, message: "不能为空", trigger: "blur" }
                ],
                campusName: [
                    { required: true, message: "不能为空", trigger: "change" }
                ],
                workAddr: [
                    { required: true, message: "不能为空", trigger: "blur" }
                ],
                postType: [
                    { required: true, message: "不能为空", trigger: "change" }
                ],
                applyReason: [
                    { required: true, message: "不能为空", trigger: "blur" }
                ],
            },


            baseurl: process.env.VUE_APP_BASE_API + "/",


            changeForm: {}, //修改勤工助学人数表单
            changeV: false,

            lookChangeV: false,

            changeLoading: false,
            changeTotal: 0,
            changeTableData: [],

            changeQueryParams: {
                pageNum: 1,
                pageSize: 10,
            },
        }

    },
    watch: {
        "applyForm.postCount"(newValue, oldValue) {
            if (newValue != 0 && !isEmpty(newValue)) {
                if (this.applyForm.willMoney != 0 && !isEmpty(this.applyForm.willMoney)) {
                    this.applyForm.willMoneyTotal = newValue * this.applyForm.willMoney;
                }
            }
        },
        "applyForm.willMoney"(newValue, oldValue) {
            if (newValue != 0 && !isEmpty(newValue)) {
                if (this.applyForm.postCount != 0 && !isEmpty(this.applyForm.postCount)) {
                    this.applyForm.willMoneyTotal = newValue * this.applyForm.postCount;
                }
            }
        },
        "applyForm.postType"(newValue, oldValue) {
            if (newValue == "固定岗位A" && !isEmpty(newValue)) {
                this.applyForm.willMoney = 1990;
            }
        },

    },
    created() {
        this.getList();
        this.initDept();
        this.getUserProfile();
    },
    methods: {

        //取消修改申请
        cancelChange(row) {
            let id = row.id;
            this.$confirm('您确定要取消该岗位的修改设岗人数申请吗, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(async () => {
                let loading = fullLoading(this);
                let res = await cancelChange(id);
                loading.close();
                if (res.code == 200) {
                    this.$message.success(res.msg);
                    this.getChangeList();
                }
            }).catch(() => {

            });
        },

        //查询修改岗位设岗人数申请记录
        async getChangeList() {
            this.changeLoading = true;
            let res = await listOwnChange(this.changeQueryParams);
            this.changeLoading = false;
            if (res.code == 200) {
                this.changeTableData = [...res.rows];
                this.changeTotal = res.total;
            }
        },

        //查看修改岗位设岗人数申请记录
        lookChangeVClick() {
            this.lookChangeV = true;
            this.getChangeList();
        },

        //修改岗位人数提交事件
        async doChange() {
            if (isEmpty(this.changeForm.newCount)) {
                this.$message.info("请输入需要修改的设岗人数");
                return;
            }
            if (isEmpty(this.changeForm.applyReason)) {
                this.$message.info("请输入申请理由");
                return;
            }

            this.changeForm.newCount = parseInt(this.changeForm.newCount);
            if (!isPositiveInteger(this.changeForm.newCount)) {
                this.$message.info("请输入正确的数字");
                return;
            }

            if (this.changeForm.newCount < this.changeForm.inCount) {
                this.$message.info("修改的设岗人数不能小于在岗人数");
                return;
            }

            let loading = fullLoading(this);
            let sdata = { ...this.changeForm };
            delete (sdata.inCount);
            delete (sdata.oldCount);
            console.log(sdata)
            let res = await doChange(sdata);
            loading.close();
            if (res.code == 200) {
                this.$message.success(res.msg);
                this.changeV = false;
            }

        },

        //修改岗位人数点击事件
        async changePostNum(row) {
            this.changeForm = {};

            let loading = fullLoading(this);
            let res = await countStuPostInByPostId(row.id); //获取岗位在岗人数
            loading.close();
            if (res.code == 200) {
                let data = { ...res.data };
                let stuPostCount = data.count;
                this.changeForm.inCount = stuPostCount;
                this.changeForm.oldCount = row.postCount;
                this.changeForm.postId = row.id;
                this.changeV = true;
            }
        },

        //此方法用于重新提交
        doReply() {
            this.$refs["replyForm"].validate(async (valid) => {
                if (valid) {
                    let sdata = { ...this.replyForm };
                    let loading = fullLoading(this);
                    let res = await doReply(sdata);
                    loading.close();
                    if (res.code == 200) {
                        this.getList();
                        this.$message.success(res.msg);
                        this.replyV = false;
                    }
                } else {
                    return false;
                }
            });
        },

        //此方法为表格中重新提交按钮的点击事件
        reVClick(data) {
            this.replyForm = {};
            this.replyForm = { ...data };
            this.replyV = true;
        },

        //此方法用于判断步骤条当前步骤的状态
        getStepStatus(data) {
            if (data == "同意") {
                return 'success';
            } else {
                return 'error';
            }
        },

        //此方法用于判断步骤条到哪个步骤了
        getStep(data) {
            if (!isEmpty(data.highCmt)) { //判断资助办领导有没有审批
                return 3;
            } else if (!isEmpty(data.deptCmt)) { //判断部门领导有没有审批
                return 2;
            } else {
                return 1;
            }
        },

        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },
        resetQuery() {
            this.resetForm("queryForm");
            this.handleQuery();
        },
        lookVClick(row) {
            this.lookForm = {};
            this.lookForm = { ...row };
            this.lookV = true;
        },
        async doEdit(row) {
            this.applyForm = { ...row };
            this.applyV = true;
        },
        cancelApply(row) {
            let id = row.id;
            this.$confirm('您确定要取消该岗位的申请吗, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(async () => {
                let loading = fullLoading(this);
                let res = await cancelApply(id);
                loading.close();
                if (res.code == 200) {
                    this.$message.success(res.msg);
                    this.getList();
                }
            }).catch(() => {

            });
        },
        async getList() {
            this.loading = true;
            let res = await listOwnApply(this.queryParams);
            this.loading = false;
            if (res.code == 200) {
                this.tableData = [...res.rows];
                this.total = res.total;
            }
        },
        async doApply() {
            this.$refs["applyForm"].validate(async (valid) => {
                if (valid) {
                    let sdata = { ...this.applyForm };
                    let loading = fullLoading(this);
                    let res = await doApply(sdata);
                    loading.close();
                    if (res.code == 200) {
                        this.getList();
                        this.$message.success(res.msg);
                        this.applyV = false;
                    }
                } else {
                    return false;
                }
            });

        },
        async doSave() {
            this.$refs["applyForm"].validate(async (valid) => {
                if (valid) {
                    let sdata = { ...this.applyForm };
                    let loading = fullLoading(this);
                    let res = await doSave(sdata);
                    loading.close();
                    if (res.code == 200) {
                        this.getList();
                        this.$message.success(res.msg);
                        this.applyV = false;
                    }
                } else {
                    return false;
                }
            });
        },
        async getUserProfile() {
            let res = await getUserProfile();
            if (res.code == 200) {
                if (!isEmpty(res.data)) {
                    this.applyForm.deptId = res.data.deptId;
                }
            }
        },
        normalizer(node) {
            if (node.children && !node.children.length) {
                delete node.children;
            }
            return {
                id: node.deptId,
                label: node.deptName,
                children: node.children,
            };
        },
        async initDept() {
            let res = await listDept();
            if (res.code == 200) {
                this.deptOptions1 = this.handleTree(res.data, "deptId");
            }
        },
        applyVClick() {
            this.applyForm.fzrNo = this.$store.getters.name;
            this.applyForm.zdlsNo = this.$store.getters.name;
            this.applyV = true;
        }
    }
}


</script>
<style scoped lang="scss">
.lookForm {
    .el-form-item {
        margin-bottom: 5px;
    }
}
</style>